import streamlit as st
import pandas as pd
import os
#import matplotlib.pyplot as plt

import Config
Config.main()


##################
# 页面设置
st.set_page_config(page_title="交易分析", page_icon="📊")
st.header("交易分析")

##################
# 对话窗口
st.session_state.P99_filefolder = st.text_input("请输入数据文件夹路径", value=st.session_state.P99_filefolder)
if os.path.exists(st.session_state.P99_filefolder):    
    st.session_state.P99_filename = st.selectbox("请选择数据文件：", options=os.listdir(st.session_state.P99_filefolder))
    st.session_state.P99_seperator = st.text_input("数据文件分隔符：", value=st.session_state.P99_seperator)
    st.session_state.P99_encoding = st.text_input("数据文件编码：", value=st.session_state.P99_encoding)
else:
    st.error("请输入正确的文件夹路径")

st.session_state.P99_head_folder = st.text_input("请输入头文件路径（否则留空）：", value=st.session_state.P99_head_folder)
if st.session_state.P99_head_folder is None:
    st.warning("未引入头文件，程序将认定数据文件自带数据头")
elif(os.path.exists(st.session_state.P99_head_folder)):
    st.session_state.P99_head_name = st.selectbox("请选择头文件：", options=os.listdir(st.session_state.P99_head_folder))
else:
    st.error("请输入正确的文件夹路径")

##################
# 显示文件信息
st.write(f"当前文件夹路径：{st.session_state.P1_filefolder}")
filepath = os.path.join(st.session_state.P1_filefolder, st.session_state.P1_filename)
st.write(f"数据文件路径：{filepath}；")
st.write(f"数据文件大小：{round(os.path.getsize(filepath)/1024, 2)}KB  /  {round(os.path.getsize(filepath)/1024/1024, 2)}MB  /  {round(os.path.getsize(filepath)/1024/1024/1024, 2)}GB")


##################
# 读取文件并预览
if st.button("运行"):
    # 读取文件
    pass
